<?php

namespace app\admin\middleware\common;

use app\common\service\LanguageService;
use think\exception\ValidateException;
use think\facade\Log;
use think\Request;

class LanguageSwitch
{
    public function handle(Request $request, \Closure $next)
    {
        $config = config('lang');
        $languageService = new LanguageService($request, $config);

        try {
            $languageService->languageSwitcher();
        } catch (ValidateException $e) {
            Log::error('Language switch failed in middleware: ' . $e->getMessage());
        }

        return $next($request);
    }
}